#include <iostream>
#include <malloc.h>
const int MinData = -100000;
const int MaxSize = 1005;
using namespace std;

typedef struct HeapStruct *Heap;
typedef struct HeapStruct{
    int *data;
    int size;
    int capacity;
};

Heap create()
{
    Heap H;
    H = (Heap)malloc(sizeof(struct HeapStruct));
    H->data = (int*)malloc(sizeof(int)*(MaxSize +1));
    H->size = 0;
    H->capacity = MaxSize;
    H->data[0] = MinData;
    return H;
}

void Insert(Heap H,int x)
{
    int i=0;
    i = ++H->size;  //数组最后一个
    for(;H->data[i/2]>x;i/=2){
        H->data[i] = H->data[i/2];
    }
    H->data[i] = x;
}

void Print(Heap H,int i)
{
    for(;i>0;i/=2){
        cout<<H->data[i];
        if(i != 1){
            cout<<" ";
        }
    }
    cout<<endl;
}

int main()
{
    Heap H;
    H = create();
    int m,n;
    cin>>m>>n;
    for(int i=0;i<m;i++){
        int temp;
        cin>>temp;
        Insert(H,temp);
    }
    for(int j=0;j<n;j++){
        int temp;
        cin>>temp;
        Print(H,temp);
    }
    return 0;
}
